import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class ModalAlert extends MIDlet implements CommandListener
{
  private Display dpl;    
  private Form fm1,fm2;      
  private Alert alt;      
  private Command cmexit, cmok, cmback;    
 
  public ModalAlert()
  {
    dpl = Display.getDisplay(this);    
    cmexit = new Command("Thoat", Command.EXIT, 1);
    cmok = new Command("Chuyen",Command.OK, 1);
    cmback = new Command("Quay lai",Command.BACK, 1);
    fm1 = new Form("Form 1");
    fm2 = new Form("Form 2");
    fm2.append("Day la dong chu trong Form 2 !");
    fm2.addCommand(cmback);
    fm1.append("Day la dong chu trong Form 1 !");    
    fm1.addCommand(cmok);
    fm1.addCommand(cmexit);
    fm1.setCommandListener(this);
    fm2.setCommandListener(this);
  }

  public void startApp()
  {
	alt = new Alert("Bat dau","Chuong trinh vua duoc mo !",null,AlertType.INFO);
      alt.setTimeout(2000);
	dpl.setCurrent(alt, fm1);    
  }

  public void pauseApp()
  { 
	alt = new Alert("Tam dung","Chuong trinh dang tam dung !",null,AlertType.WARNING);
      alt.setTimeout(2000);
	dpl.setCurrent(alt, fm1);    
  }

  public void destroyApp(boolean unconditional)
  {
  }
  public void commandAction(Command c, Displayable s)
  {
    if (c == cmexit)
    { 
      destroyApp(true);
      notifyDestroyed();
    }
    if (c == cmok)
    {
	alt = new Alert("Doi form","Ban da chuyen sang Form 2 !",null,AlertType.INFO);
      alt.setTimeout(2000);
   	dpl.setCurrent(alt, fm2);
    }
    if(c == cmback)
    {
	alt = new Alert("Doi form","Ban da tro lai Form 1 !",null,AlertType.INFO);
      alt.setTimeout(2000);
   	dpl.setCurrent(alt, fm1);
    }
  }
}
